/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By
 * Copyright authorization contact 18814114118
 */
package com.shop.cereshop.business.controller;

import com.shop.cereshop.business.annotation.NoRepeatSubmit;
import com.shop.cereshop.business.param.shop.ShopQualificationParam;
import com.shop.cereshop.business.service.shop.CereShopQualificationService;
import com.shop.cereshop.commons.domain.business.CerePlatformBusiness;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 店铺资质认证控制器
 */
@RestController
@RequestMapping("shopQualification")
@Slf4j(topic = "ShopQualificationController")
@Api(value = "店铺资质认证模块", tags = "店铺资质认证模块")
public class ShopQualificationController {

    @Autowired
    private CereShopQualificationService cereShopQualificationService;

    /**
     * 提交店铺资质认证
     */
    @PostMapping(value = "submit")
    @NoRepeatSubmit
    @ApiOperation(value = "提交店铺资质认证")
    public Result<String> submitQualification(@RequestBody @Validated ShopQualificationParam param, HttpServletRequest request) throws CoBusinessException {
        CerePlatformBusiness user = (CerePlatformBusiness) request.getAttribute("user");
        String result = cereShopQualificationService.submitQualification(param, user);
        return Result.success(result);
    }

    /**
     * OCR识别营业执照
     */
    @PostMapping(value = "recognizeLicense")
    @ApiOperation(value = "OCR识别营业执照")
    public Result<Object> recognizeBusinessLicense(@ApiParam(value = "营业执照图片URL", required = true) @RequestParam String imageUrl) throws CoBusinessException {
        Object result = cereShopQualificationService.recognizeBusinessLicense(imageUrl);
        return  Result.success(result);
    }

    /**
     * 获取店铺认证状态
     */
    @GetMapping(value = "status/{shopId}")
    @ApiOperation(value = "获取店铺认证状态")
    public Result<Object> getQualificationStatus(@ApiParam(value = "店铺ID", required = true) @PathVariable Long shopId) throws CoBusinessException {
        Object result = cereShopQualificationService.getQualificationStatus(shopId);
        return Result.success(result);
    }

    /**
     * 更新店铺资质认证
     */
    @PostMapping(value = "update")
    @NoRepeatSubmit
    @ApiOperation(value = "更新店铺资质认证")
    public Result<String> updateQualification(@RequestBody @Validated ShopQualificationParam param, HttpServletRequest request) throws CoBusinessException {
        CerePlatformBusiness user = (CerePlatformBusiness) request.getAttribute("user");
        String result = cereShopQualificationService.updateQualification(param, user);
        return Result.success(result);
    }
}
